/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xmlProject.listener;

import com.xmlProject.DTO.ProductDTO;
import com.xmlProject.ultils.DBUltils;
import com.xmlProject.ultils.XMLUltils;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import sample.accounts.Products;

/**
 * Web application lifecycle listener.
 * @author Admin
 */
public class ContextListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent sce) {
        Products products = new Products();
        ProductDTO[] result = DBUltils.getProductInfos();
        for (int i = 0; i < result.length; i++) {
            products.getProduct().add(result[i].getProductINFO());
        }
        XMLUltils.MarshallingProductsInfo(products, sce.getServletContext().getRealPath("/") + "WEB-INF/products.xml");
    }

    public void contextDestroyed(ServletContextEvent sce) {
    }
}
